﻿using System;
using System.Collections;
using System.Text;
using System.Configuration;
using System.Xml;
using System.Collections.Generic;
using AbstraX;

namespace SolutionFramework
{
    public class VSTemplateLocationsHandler : IConfigurationSectionHandler
    {
        public object Create(object parent, object configContext, XmlNode section)
        {
            var locations = new List<CustomTemplateLocation>();

            // Gets the child element names and attributes.
            foreach (XmlNode child in section.ChildNodes)
            {
                if (XmlNodeType.Element == child.NodeType)
                {
                    var location = new CustomTemplateLocation();

                    foreach (XmlAttribute childAttrib in child.Attributes)
                    {
                        if (XmlNodeType.Attribute == childAttrib.NodeType)
                        {
                            if (childAttrib.Name == "templateLocation")
                            {
                                location.TemplateLocation = childAttrib.Value;
                            }
                            else if (childAttrib.Name == "commonLocation")
                            {
                                location.CommonLocation = childAttrib.Value;
                            }
                        }
                    }

                    locations.Add(location);
                }
            }

            return locations;
        }
    }
}